<?php

namespace App\Http\Controllers\Mobile;

use App\Http\Helpers\Crypter;
use App\Http\Helpers\Sign;
use App\Http\Services\QuestionService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
    /**
     *获取aiSee的url
     * @author: lican<364548233@qq.com>
     */
    public function getAiseeUrl(Request $request){
        $this->validate($request, [
            'user' => 'required'
        ]);
        $user = $request->input('user');
        $userId = $user['name']."(".$user['card_number'].")"."[".$user['school']['name']."]"."|".$user['school']['code'];
        $feedbackId = trim($request->input('feedbackId')) ?? '';
        $crypter = new Crypter();
        $data = [
            'userid' => $userId,
            'ip' => Sign::getClientIp(),
//            'hardware' => Sign::getPhoneModel(),
            'os' => php_uname('s').php_uname('r'),
            't' => time()
        ];
        $decrypt = [
//            'color' => "08c27c",

        ];

        $url = $crypter::getAuthorizedUrl(BASE_URL, $data, $decrypt);

        header("location:{$url}");
    }

    /**
     *移动端首页
     * @author: lican<364548233@qq.com>
     */
    public function index(Request $request){
        $this->validate($request, [
            'user' => 'required'
        ]);
        $user = $request->input('user'); //移动端登录用户信息
        $data = QuestionService::getQuestion($user);
        $high = QuestionService::getHign($user['school']['id'], $user['card_number']);
        $data = $data['list'];
        $high = $high['list'];
        return view('mobile.center.index', compact('data', 'high'));
    }

    /**
     *banner2
     * @author: lican<364548233@qq.com>
     */
    public function banner2(Request $request){
        $user = $request->input('user');
        $list = QuestionService::getCommonQuestion($user);

        return view('mobile.center.cinema.index', compact('list'));
    }

    /**
     *banner3
     * @author: lican<364548233@qq.com>
     */
    public function banner3(Request $request){
        $user = $request->input('user');
        return view('mobile.center.mycenter.index', compact('user'));
    }

    /**
     *问题添加页
     * @author: lican<364548233@qq.com>
     */
    public function feedback(Request $request){
        return view('mobile.feedback.index');
    }

    /**
     *问题详情
     * @author: lican<364548233@qq.com>
     */
    public function detail(Request $request){
        $this->validate($request, [
            'id' => 'required|int'
        ]);
        $id = (int)$request->input('id');
        $user = $request->input('user');
        $res = QuestionService::getQuestionById($user, $id);
        $question = $res['question'];
        return view('mobile.center.detail.index', compact('question'));

    }



}
